--快人一步
local kuairenyibu = fk.CreateSkill {
    name = "mcdh_kuairenyibu"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

kuairenyibu:addEffect(fk.EventPhaseStart,{
can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and target == player and player.phase == Player.Play
    end,
    on_cost = function(self, event, target, player, data)
            local room = player.room
            local card = room:askForCard(player,1,1,true,self.name,true,".","#kuairenyibu-push")
            if #card ~= 0 then
                self.cost_data = card
                return true
            end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:moveCardTo(self.cost_data, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, false)
        local use = room:askToUseVirtualCard(player,{name="slash",skill_name=self.name,prompt = "#kuairenyibu",cancelable=false,extra_data={bypass_times = true,extraUse = true},skip=true})
        if use then
            use.extra_data  = {}
            use.extra_data.kuairenyibu = player
            room:useCard(use)
        end

    end
})

kuairenyibu:addEffect(fk.Damage,{
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        local logic = room.logic
        if data.card and data.card.trueName == "slash" and table.contains(data.card.skillNames,self.name) then
        local damageEvent = logic:getCurrentEvent()
        local useEvent =  damageEvent:findParent(GameEvent.UseCard)
        return  useEvent and useEvent.data.extra_data and useEvent.data.extra_data.kuairenyibu == player
        end
    end,
    on_cost = function(self, event, target, player, data)
            return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local judge = {
            who = player,
            reason = self.name,
            pattern = ".",
            skipDrop = false,
        }
        room:judge(judge)
        if judge.card.trueName ~= "slash" then
            room:setPlayerMark(player,"@@kuairenyibu-phase",1)
        end
    end
})

kuairenyibu:addEffect('prohibit',{
     prohibit_use = function(self, player, card)
        return player:getMark("@@kuairenyibu-phase") ~= 0
    end,
    prohibit_response = function(self, player, card)
        return false
    end,
})
Fk:loadTranslationTable {
    ["mcdh_kuairenyibu"] = "先攻",
    [":mcdh_kuairenyibu"] = "『快人一步』<br>出牌阶段开始时,你可以将一张牌至于牌堆顶,然后视为使用一张【杀】,此【杀】造成伤害后,你判定,若结果不为【杀】，你本阶段不能使用牌。",
    ["@@kuairenyibu-phase"] = "快人一步",
    ["#kuairenyibu-push"] = "快人一步：将一张牌至于牌堆顶",
    ["#kuairenyibu"] = "快人一步：视为使用一张【杀】"
}

return kuairenyibu